/**

 * 
 */
package com.yufei.infoExtractor.io.impl;

import java.io.IOException;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.yufei.infoExtractor.io.AbstractHttpDataRetriever;
import com.yufei.infoExtractor.io.DataRetrieverFeatures;
import com.yufei.infoExtractor.util.CommonUtil;


/**
 * created by @author jasstion at 2012-9-17
 */
public class CommonDataRetriever extends AbstractHttpDataRetriever {

	/**
	 * @param dataRetrieverFeatures
	 */
	public CommonDataRetriever(DataRetrieverFeatures dataRetrieverFeatures) {
		super(dataRetrieverFeatures);
		// TODO Auto-generated constructor stub
	}
	/* (non-Javadoc)
	 * @see com.rzx.crawler.io.AbstractHttpDataRetriever#getHtmlContent()
	 */
	@Override
	public String getHtmlContent() {
		// TODO Auto-generated method stub
		return CommonUtil.getStrFromInputStream(inputStream, null);
	}
	@Override
	public void connect() throws IOException {
		// TODO Auto-generated method stub
		HttpClient httpclient = new DefaultHttpClient();
		HttpGet httpget = null;
		try {
			httpget = new HttpGet(url.toURI());
			
		} catch (URISyntaxException e) {
		}
		HttpResponse response = httpclient.execute(httpget);
		
		HttpEntity entity = response.getEntity();
		if (entity != null) {
		     inputStream = entity.getContent();
		  
		}
	}

	@Override
	public void disconnect() throws IOException {
		// TODO Auto-generated method stub
		try{
			inputStream.close();
		}finally{
		}

	}

	@Override
	public long getContentLenght() throws IOException {
		// TODO Auto-generated method stub
		return 0;
	}
	








}
